#include"shared.hpp"

int main(){

    //先生成一个key值
    key_t k=GetKey();
    printf("A 获取key值成功: %d\n",k);

    //创建共享内存，有就获取标识码shmid
    int shmid=Getshm(k);
    printf("A 获取共享内存块成功\n");

    //关联共享内存块
    char* p = (char*)attachshm(shmid);
    if (p == (void*)-1) {
        perror("shmat failed");
        delshm(shmid);
        printf("A 删除共享内存成功\n");
        exit(EXIT_FAILURE);
    }
    printf("A 关联共享内存块成功\n");
    

    //开始写入：
     const char* str = "i am process A";
     snprintf(p, MAXSIZE, "%s", str);

    //去关联
    detachshm(p);

    printf("A 去关联成功\n");
   
    return 0;
}

